import http from '@/utils/request.js'

export default {
    getAdminName: () => {
        return http({
                url: '/api/admin/getAdminName',
                method: 'get',
            }
        )
    },
    editAdminInfo: (obj) => {
        return http({
                url: '/api/admin/edit',
                method: 'put',
                data: obj,
                headers: {
                    //定义将数据以json的形式传入后台(java)
                    'Content-Type': 'application/json'
                }
            }
        )
    },
    updatePassword: (obj) => {
        return http({
                url: '/api/admin/updatePassword',
                method: 'put',
                data: obj,
                headers: {
                    //定义将数据以json的形式传入后台(java)
                    'Content-Type': 'application/json'
                }
            }
        )
    },
    // 修改：头像上传接口，接收 File 类型的文件
    uploadAvatar: (file) => { // 参数改为直接接收 File 对象（用户选择的图片）
        const formData = new FormData(); // 关键：用 FormData 封装参数
        formData.append('file', file); // 关键：参数名必须是 'file'，与后端 @RequestParam("file") 对应

        return http({
            url: '/api/admin/avatar', // 注意：后端接口是 /api/admin/avatar，确保URL与后端一致
            method: 'post',
            data: formData, // 传递 FormData 对象
        });
    },
    // 获取：头像接口
    getAvatarUrl: () => {
        return http({
            url: '/api/admin/url',
            method: 'get',
        });
    },
    getUserInfo: (obj) => {
        return http({
            url: '/api/admin/getUserInfo',
            method: 'get',
            params: obj
        });
    },
    getAdminInfo: (obj) => {
        return http({
            url: '/api/admin/getAllAdmins',
            method: 'get',
            params: obj
        });
    },
    deleteUser: (id) => {
        return http({
            url: `/api/admin/deleteUser/${id}`,
            method: 'put',
        });
    },
    updateUser: (id) => {
        return http({
            url: `/api/admin/updateUser/${id}`,
            method: 'put',
        });
    },
    getInfo: () => {
        return http({
            url: '/api/admin/info',
            method: 'get',
        });
    },
}